<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class personnelgroups {
  function loaddata() {
    global $masterclass;

    $masterclass->loadjavascript('personnel','index.js');
    $masterclass->websiteconfig['body_onload'].="personnelgroup_search('load_personnelgroupsearch',document.getElementById('personnelgroupval').value);";

    $masterclass->websiteconfig['title'].=' - Personnel Groups';
  return;
  }
  function load_personnelgroupsearch() {
    global $masterclass;

    $ret='';

    $personnelgroupname=$_POST['rsargs'][1];
    $searchtype=$_POST['rsargs'][2];
    $pg=$_POST['rsargs'][3];

/* Create Search Query */
    if ($personnelgroupname!='') {
      $arrsearch[]="(`name` LIKE '%".$masterclass->allclasses['mysql_functions']->formatmysqlstr($personnelgroupname)."%')";
    }

    if (!empty($arrsearch)) {
      $strsearch='';
      foreach ($arrsearch as $str) {
        if ($strsearch!='') { $strsearch.=' OR '; }
        $strsearch.=' ('.$str.') ';
      }
    }

    $strsql = "SELECT * FROM `personnelgroups`";
    if ($strsearch!='') { $strsql.=" WHERE $strsearch "; }
    $strsql .= " ORDER BY `name` ";
    $query = $masterclass->allclasses['mysql_functions']->fetch_assoc($strsql);

    $ret.=$masterclass->allclasses['websites']->sitebox_vspacer();
    $ret.=$masterclass->allclasses['websites']->sitebox_start('100%');
    $ret.=$masterclass->allclasses['websites']->sitebox_headline('Personnel Groups','');
    if (!empty($query)) {
      $ret.='<table width="100%" cellpadding="1" cellspacing="0" border="0">';
      $ret.='<tr valign="bottom" class="sitebox_content" style="background-color:#CCCCCC;">';
      $ret.='<td style="border-bottom:1px solid;"><b>Name</b></td>';
      $ret.='</tr>';
      foreach ($query as $result) {
        $name='';
        $name=$result['name'];

        $ret.='<tr valign="top" OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'personnel/editpersonnelgroups.php?personnelgroupid='.$result['id'].'\',\'editpersonnelgroup'.$result['id'].'\',\'760\',\'480\');" style="cursor:pointer;" class="sitebox_content" OnMouseOver="this.className=\'sitebox_content_mouseover\'" OnMouseOut="this.className=\'sitebox_content\'" >';
        $ret.='<td style="border-bottom:1px solid;">'.$name.'&nbsp;</td>';
        $ret.='</tr>';
      }
      $ret.='</table>';
    } else {
      $ret.='<table width="100%" cellpadding="1" cellspacing="0" border="0">';
      $ret.='<tr valign="bottom" class="sitebox_content" style="background-color:#CCCCCC;">';
      $ret.='<td style="border-bottom:1px solid;">No Personnel Groups</td>';
      $ret.='</tr>';
      $ret.='</table>';
    }
    $ret.=$masterclass->allclasses['websites']->sitebox_end();

    $masterclass->site['grabdata_vars']['load_personnelgroupsearch']=$ret;
  }

  function display() {
  global $masterclass;

  $searchpersonnel_click="personnelgroup_search('load_personnelgroupsearch',document.getElementById('personnelgroupval').value);";
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top">
    <td>
<?php
  echo $masterclass->allclasses['websites']->sitebox_pageheader('Search Personnel Groups','');
  $nav='';
  $nav.='<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr valign="middle" class="sitebox_navigation">';
  $nav.='<td width="50"><nobr>Search:&nbsp;&nbsp;</nobr></td>';
  $nav.='<td valign="middle" style="padding-left:2px;text-align:left;"><nobr><input type="text" name="personnelgroupval" id="personnelgroupval" size="15">&nbsp;&nbsp;<input type="button" class="button" OnClick="hide(document.getElementById(\'maincontainer\'));show(document.getElementById(\'loadingcontainer\'));'.$searchpersonnel_click.'" value=" Search "></nobr>&nbsp;&nbsp;<input type="button" class="button" value="New Personnel Group" OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'personnel/editpersonnelgroups.php\',\'newpersonnelgroup\',\'760\',\'480\');">&nbsp;&nbsp;<input type="button" class="button" value="Close" OnClick="closewindow();"></td>';
  $nav.='</tr></table>';
  echo $masterclass->allclasses['websites']->sitebox_navigation($nav);
?>
    </td>
  </tr>
</table>

<table width="100%" cellpadding="2" cellspacing="5" border="0">
  <tr valign="top">
    <td>
    <div id="personnelgroup_searchlist" class="sitebox_content"></div>
</td></tr></table>
<?php

  return;
  }
}
?>